/**
 * 组织架构树形结构转换
 */
export default {
    /**
     *  组织架构中部门树形结构转换
     * @param treeList   转换的数据源
     * @param rederPartment  部门渲染函数
     * @param renderPerson   人员渲染函数
     * @returns {*}      转换的结果
     */
    transformationDepartTree(data, rederPartment) {
        //递归，用于将数据进行改造封装
        data.forEach((val, index) => {
            handelTreeData(val);
        });

        function handelTreeData(currentFloor) {
            if(currentFloor.expand){
                currentFloor.expand = true;
            }else{
                currentFloor.expand = false;
            }
            currentFloor.expand = false;
            currentFloor.render = rederPartment;
            currentFloor.children = [];
            currentFloor.title = currentFloor.depName;
            if (currentFloor.managers && currentFloor.managers.length) {
                currentFloor.children = [...currentFloor.managers];
                currentFloor.children.forEach((val, index) => {
                    val.clicked = false;
                    val.render = rederPartment;
                    // val.title = val.name;
                    // self.allManagers.push({...val});
                });
            }
            if (!currentFloor.childDepInfos) {
                return;
            } else {
                //如果有下级部门
                currentFloor.children.push(...currentFloor.childDepInfos);
                currentFloor.children.forEach((val, index) => {
                    handelTreeData(val);
                })
            }
        }
        return [...data];
    }
};
